package ct.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

public class MainFrame extends JFrame {

	private static final long serialVersionUID = 1L;

	private MainDesktop desktop;
	private MainMenuBar menubar;

	public MainFrame() {

		super();

		configureFrame();

		menubar = new MainMenuBar(this);
		this.setJMenuBar(menubar);

		JPanel content = new JPanel(new BorderLayout());
		desktop = new MainDesktop();
		content.add(desktop, BorderLayout.CENTER);

		this.setContentPane(content);
	}

	private void configureFrame() {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		this.setTitle("Calcul de  courbe de taux");
		this.setSize(screenSize.width, screenSize.height - 30);
		this.setPreferredSize(new Dimension(screenSize.width,
				screenSize.height - 30));
		this.setLocation(0, 0);
		this.setResizable(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public MainDesktop getDesktop() {
		return desktop;
	}

}

class MainMenuBar extends JMenuBar {

	private static final long serialVersionUID = 1L;
	private MainFrame parent;

	protected MainMenuBar(MainFrame parent) {
		super();
		this.parent = parent;
		configureBar();
	}

	private void configureBar() {

		JMenu Mfichier = new JMenu("Menu");

		JMenuItem Iportefeuille = new JMenuItem("Portefeuille");
		Iportefeuille.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				parent.getDesktop().addFrame(new FenetrePortefeuille());
			}
		});
		
		JMenuItem IHaoLee = new JMenuItem("Calcul de prix d'option");
		IHaoLee.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				parent.getDesktop().addFrame(new FenetreHaoLee());
			}
		});

		JMenuItem Ioptions = new JMenuItem("Options");
		Ioptions.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new FenetreOptions().setVisible(true);
			}
		});
		
		JMenuItem Iquitter = new JMenuItem("Quitter");
		Iquitter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});

		Mfichier.add(Ioptions);
		Mfichier.add(Iportefeuille);
		Mfichier.add(IHaoLee);
		Mfichier.addSeparator();
		Mfichier.add(Iquitter);

		this.add(Mfichier);
	}

}
